#include <map>
#include <vector>

#include "../include/simulatormanager.h"
#include "../include/card.h"
#include "../include/deck.h"

using namespace std;

namespace mtga {

	SimulatorManager::SimulatorManager(UserState* userState) {
		cout << "Creating SimulatorManager (" << this << ")" << endl;
		this->userState = userState;
	}

	SimulatorManager::~SimulatorManager() {
		cout << "Releasing SimulatorManager (" << this << ")" << endl;
	}

	void SimulatorManager::init() {
		int handSize = 7;
		do {
			this->userState->init();
			this->userState->suffleLibrary();
			this->userState->drawCard(handSize);
			cout << "Cards in hand:" << endl;
			for (unsigned i = 0; i < userState->getHand().size(); i++) {
				cout << "    " << i + 1 << ": " << userState->getHand()[i]->getName() << std::endl;
			}
			bool keep;
			std::string option;
			while (true) {
				cout << "Keep hand? [y/n]: ";
				cin >> option;
				if (option.compare("y") == 0 || option.compare("n") == 0) {
					keep = option.compare("y") == 0;
					break;
				}
				cout << "Invalid option" << std::endl;
			}
			if (!keep && handSize > 1) {
				handSize--;
			} else {
				cout << "Next draws:" << std::endl;
				for (unsigned i = 0; i < 10; i++) {
					cout << "    " << i + 1 << ": " << userState->getLibrary()[i]->getName() << std::endl;
				}
				break;
			}
		} while (true);

	}
}
